<template>
  <div class="goods-info" v-if="Object.keys(detailInfo).length !== 0">
    <div class="info-desc clear-fix">
      <div class="start">
      </div>
      <div class="desc">{{detailInfo.desc}}</div>
      <div class="end"></div>
    </div>
    <div class="info-key">{{detailInfo.detailImage[0].key}}</div>
    <div class="info-list">
      <img :src="item" alt="" v-for="(item,index) in detailInfo.detailImage[0].list" :key="index" @load="imgLoad">
    </div>
  </div>
</template>

<script>
  export default {
    name : "DetailGoodsInfo",
    props:{
      detailInfo:{
        type : Object,
        default(){
          return {}
        }
      }
    },
    data(){
      return {
        counter : 0,
        imagesLength : 0
      }
    },
    methods : {
    imgLoad(){
      // 判断，所有的图片都加载完了，那么进行一次回调就行了
      if(++this.counter === this.imagesLength){
        this.$emit("imagesload",true)
        console.log("在DGinfo组件中触发了回调，这句话是加入购物车的关键")
      }
    }
    },
    watch:{
      detailInfo(){
        // 获取图片的个数
        this.imagesLength = this.detailInfo.detailImage[0].list.length
      }
    }
  }
</script>

<style scoped>
  .goods-info{
    padding:20px 0;
    border-bottom:5px solid #f2f5f8;
  }
  .info-list img{
    width: 100%;
    /* height: 300px; */
  }
</style>
